#!/usr/bin/env python3
"""
精确整数类型测试模块

本模块包含各种精确整数类型的测试函数，用于验证 MCPy 编译器
对精确整数类型的支持和转换能力。
"""

from mc.types import (
    int8_t,
    int16_t,
    uint32_t,
    uint64_t,
    size_t,
    ptrdiff_t,
    intptr_t,
)
from gtest import EXPECT_EQ


def test_precise_int8(x: int8_t) -> int8_t:
    """int8 类型测试"""
    return x + 1


def test_precise_uint32(x: uint32_t) -> uint32_t:
    """uint32 类型测试"""
    return x * 2


def test_precise_size_t(x: size_t) -> size_t:
    """size_t 类型测试"""
    return x + 10


def test_mixed_precise_types(a: int8_t, b: uint32_t, c: size_t) -> size_t:
    """混合精确整数类型测试"""
    return a + b + c


def test_int16_operations(x: int16_t, y: int16_t) -> int16_t:
    """int16 类型运算测试"""
    return x * y + 100


def test_uint64_large_numbers(x: uint64_t) -> uint64_t:
    """uint64 大数测试"""
    return x + 1000000000


def test_ptrdiff_t_pointer_arithmetic(base: ptrdiff_t, offset: ptrdiff_t) -> ptrdiff_t:
    """ptrdiff_t 指针算术测试"""
    return base + offset


def test_intptr_t_address_operations(addr: intptr_t) -> intptr_t:
    """intptr_t 地址操作测试"""
    return addr + 8  # 假设指针偏移8字节


def run_all_precise_type_tests() -> None:
    """运行所有精确整数类型测试"""
    # int8 测试
    int8_result = test_precise_int8(126)
    EXPECT_EQ(int8_result, 127)

    # uint32 测试
    uint32_result = test_precise_uint32(1000000)
    EXPECT_EQ(uint32_result, 2000000)

    # size_t 测试
    size_t_result = test_precise_size_t(100)
    EXPECT_EQ(size_t_result, 110)

    # 混合类型测试
    mixed_result = test_mixed_precise_types(10, 20, 30)
    EXPECT_EQ(mixed_result, 60)

    # int16 测试
    int16_result = test_int16_operations(50, 60)
    EXPECT_EQ(int16_result, 3100)

    # uint64 测试
    uint64_result = test_uint64_large_numbers(9223372036854775807)
    EXPECT_EQ(uint64_result, 9223372037854775807)

    # ptrdiff_t 测试
    ptrdiff_result = test_ptrdiff_t_pointer_arithmetic(1000, 200)
    EXPECT_EQ(ptrdiff_result, 1200)

    # intptr_t 测试
    intptr_result = test_intptr_t_address_operations(0x7FFF12345678)
    EXPECT_EQ(intptr_result, 0x7FFF12345680)
